#-*-coding:utf-8-*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import unittest
from time import sleep
from selenium.webdriver.common.by import By
from DriverAndUnit import myunit,myfunction
from LbtFront.Base.LoginPage import login
from Resources.UserName import lbtUserName
from Resources.UserName import lbtUserPassword
from Resources import UserName



class loginTest(myunit.myTest):
    """测试用户登录"""
    def user_login_verify(self, username='', password=''):
        login(self.driver).user_login(username, password)
    def test_loginSuccess(self):
        '''用户名密码正确'''
        self.user_login_verify(lbtUserName, lbtUserPassword)
        sleep(3)
        po=login(self.driver)
        '''选择学校，并登录，且验证登录后的用户名是否正确，并拍照'''
        po.choiceSchool('btn_rolse','乐贝通幼儿园')
        '''print(po.user_login_success())'''
        self.assertEqual(po.user_login_success(),UserName.lbtUserNameInfo)
        myfunction.insert_img(self.driver,'test_loginSuccess.png')
    def test_loginNopassword(self):
        '''密码为空'''
        self.user_login_verify(lbtUserName, '')
        sleep(3)
        po=login(self.driver)
        self.assertEqual(po.driver.find_element(By.CLASS_NAME,'denglukuang-p1').text,'智慧校园管理云平台')
        myfunction.insert_img(self.driver,'test_loginNopassword.png')
    def test_loginNousername(self):
        '''用户名为空'''
        self.user_login_verify('', lbtUserPassword)
        sleep(3)
        po=login(self.driver)
        self.assertEqual(po.driver.find_element(By.CLASS_NAME,'denglukuang-p1').text,'智慧校园管理云平台')
        myfunction.insert_img(self.driver,'test_loginNousername.png')
    def test_loginErrorPass(self):
        '''密码错误'''
        self.user_login_verify(lbtUserName, '012346')
        sleep(3)
        po=login(self.driver)
        alert=self.driver.switch_to_alert()
        alert.accept()
        self.assertEqual(po.driver.find_element(By.CLASS_NAME,'denglukuang-p1').text,'智慧校园管理云平台')
        myfunction.insert_img(self.driver,'test_loginErrorPass.png')
if __name__=='__main__':
    unittest.main()